#include <iostream>
using std::cout;
using std::endl;
class Point{
public:
    Point(int x, int y)
    :_x(x)
    ,_y(y)
    {
        //cout << "Point(int,int)" << endl;
        cout << "Point(" << _x << "," << _y << ")" << endl;
    }

    ~Point(){
        cout << "~Point(" << _x << "," << _y << ")" << endl;
    }
    Point(const Point & rhs)
    :_x(rhs._x)
    ,_y(rhs._y)
    {
        cout << "Point(const Point &)" << endl;
    }
    void print(){
        cout << "(" << _x << "," << _y << ")";
    }

private:
    int _x;
    int _y;
};

class Line{
public:
    //注意此时初始化列表中的写法
    //_pt1 不再是= x1, y1而是调用了构造函数
    Line(int x1, int y1, int x2, int y2)
    :_pt1(x1, y1)
    ,_pt2(x2, y2)
    {
        cout << "Line(int,int,int,int)" << endl;
    }

    void printLine(){
        _pt1.print();
        cout << "----->";
        _pt2.print();
        cout << endl;
    }
    ~Line(){
        cout << "~Line()" << endl;
    }


private:
    //这俩数据成员对象，谁先创建出来 
    //  按照声明的先后顺序进行创建
    //销毁的时候，又是谁先销毁回收呢？
    //  按照声明的逆序先销毁
    Point _pt1;
    Point _pt2;
};



void test(){
    //6和8的逻辑不太一样的
    //6：point对象时在line中构造出来的
    //8：是提前先构造出来的
    Line line(1, 2, 3, 4);
    line.printLine();
}

int main()
{
    test();
    return 0;
}

